//
//  TKYSearchBarTextFiled.m
//  ProgressReportProject
//
//  Created by apple on 2018/4/23.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYSearchBarTextFiled.h"

@implementation TKYSearchBarTextFiled
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(kWidthScale *15, 5, kScreenWidth- kWidthScale* 30, kHeightScale *35)];
    //创建左侧视图
    UIImage *im = [UIImage imageNamed:@"search"];
    UIImageView *iv = [[UIImageView alloc] initWithImage:im];
    UIView *lv = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth- kWidthScale* 240, 0, 20, 20)];//宽度根据需求进行设置，高度必须大于 textField 的高度
    iv.center = lv.center;
    [lv addSubview:iv];
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = lv;
    
    textField.placeholder = @"搜索";
    textField.textAlignment = NSTextAlignmentCenter;
    textField.backgroundColor = kRGBColor(248, 248, 248, 1);
    textField.userInteractionEnabled = NO;
    [textField tky_cornerWithRadius:5 borderColor:nil borderWidth:0];
    self.textField = textField;
    [self addSubview:textField];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, kScreenWidth, kHeightScale *35);
    [button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
}

- (void)clickAction:(UIButton *)button{
    if (self.seachbarBlock) {
        self.seachbarBlock(button);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
